//
//  YGNetworkManager.swift
//  SwiftWebo
//
//  Created by 王勇 on 2018/5/30.
//  Copyright © 2018年 Brave. All rights reserved.
//

import UIKit
import AFNetworking

enum RequstTypeMethon {
    case GET
    case POST
}

/// 通用请求工具类
class YGNetworkManager: AFHTTPSessionManager {
    
    //单例
    static let sharedManager = YGNetworkManager()

    /// 普通get、post请求
    func NomalRequst(requstType:RequstTypeMethon = .GET, URLString:String, parameters:[String:AnyObject]?,completion:@escaping(_ jsonData:Any?,_ isSuccess:Bool)->()){
        
        let success = { (task:URLSessionDataTask,jsonData:Any?)->() in
           completion(jsonData,true)
        }
        let failure = { (task:URLSessionDataTask?,error:Error)->() in
            
            completion(nil, false)
        }
        
        if requstType == .GET {
            get(URLString, parameters: parameters, progress:nil, success: success, failure:failure)
        }else{
            
            post(URLString, parameters: parameters, progress:nil, success:success, failure:failure)
        }
        
        
        
        
        
        
        
    }
    
    
}
